﻿#include "TropCrr.h"

TropCrr::~TropCrr()
{
}

double TropCrr::cal_saastamoinen(BLH blh, double ele)
{
    double Pi = this->mCons->get_Pi();
    double r2d = this->mCons->get_r2d();
    double hgt, pres, temp, e, z, trph, trpw;

    if (blh.H < -100.0 || 1E4 < blh.H || ele <= 0) return 0.0;

    /* 计算标准气象元素 */
    const double temp0 = 15.0;/* 海平面（海拔 0m）温度 */
    const double humi = 0.70;/* 相对湿度 （%）*/

    hgt = blh.H < 0.0 ? 0.0 : blh.H;
    pres = 1013.25 * pow(1.0 - 2.2557E-5 * hgt, 5.2568);/* 气压 */
    temp = temp0 - 6.5E-3 * hgt + 273.16;               /* 温度 */
    e = 6.108 * humi * exp((17.15 * temp - 4684.0) / (temp - 38.45));/* 湿度 */

    /* saastamoninen 模型 */
    z = Pi / 2.0 - ele;
    trph = 0.0022768 * pres / (1.0 - 0.00266 * cos(2.0 * blh.B) - 0.00028 * hgt / 1E3) / cos(z);
    trpw = 0.002277 * (1255.0 / temp + 0.05) * e / cos(z);
    return trph + trpw;
}

double TropCrr::get_tropCorr(BLH blh, double ele)
{
    return this->cal_saastamoinen(blh, ele);
}